﻿//
//  LZ09_F3.cs
//
//  Author:
//       Antonio J. Nebro <antonio@lcc.uma.es>
//
//  Copyright (c) 2011 Antonio J. Nebro
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using jmetal.core;
using jmetal.encodings.solutionType;

namespace jmetal.problems
{
  public class LZ09_F3 : Problem {
    LZ09 LZ09_ ;

    public LZ09_F3(String solutionType):this(solutionType, 21, 1, 23) {
  } // LZ09_F3
  
  /** 
   * Creates a LZ09_F3 problem instance
   * @param solutionType The solution type must "Real" or "BinaryReal". 
   */
   public LZ09_F3(String solutionType,
                  int ptype,
                  int dtype,
                  int ltype)  {
     numberOfVariables_  = 30;
     numberOfObjectives_ = 2;
     numberOfConstraints_= 0;
     problemName_        = "LZ09_F3";
         
     LZ09_  = new LZ09(numberOfVariables_, 
                       numberOfObjectives_, 
                       ptype, 
                       dtype, 
                       ltype) ;

     lowerLimit_ = new double[numberOfVariables_];
     upperLimit_ = new double[numberOfVariables_];

     lowerLimit_[0] = 0.0 ;
     upperLimit_[0] = 1.0 ;
     for (int var = 1; var < numberOfVariables_; var++){
       lowerLimit_[var] = -1.0;
       upperLimit_[var] = 1.0;
     } //for
         
      if (solutionType == "Real")
        solutionType_ = new RealSolutionType (this);
   } // LZ09_F1
   
   /** 
    * Evaluates a solution 
    * @param solution The solution to evaluate
     * @throws JMException 
    */    
    public override void evaluate (Solution solution)
    {
      // <pex>
      if (solution == (Solution)null)
        throw new ArgumentNullException("solution");
      // </pex>
      Variable[] gen = solution.variable_ ;
      
      List<Double> x = new List<Double>(numberOfVariables_) ;
      List<Double> y = new List<Double>(numberOfObjectives_);
          
      for (int i = 0; i < numberOfVariables_; i++) {
        x.Add(gen[i].value_);
        y.Add(0.0) ;
      } // for
        
      LZ09_.objective(x, y) ;
      
      for (int i = 0; i < numberOfObjectives_; i++)
        solution.objective_[i] = y[i];
    } // evaluate
  }
}
